package com.mspbots.attendance.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mspbots.attendance.model.Attendance;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * com.mspbots.core.mapper.TenUserTimeLogMapper
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/6/19
 */
@Mapper
public interface AttendanceMapper extends BaseMapper<Attendance> {

    /**
     * Override super page and  tenant name tenant user name
     *
     * @param page         page model
     * @param queryWrapper query
     * @return page model
     */
    @Select(value = "SELECT attendance.*,b.firstname AS firstName,b.lastname AS lastName,c.name AS tenantName " +
            "FROM tenant_user_attendances attendance " +
            "LEFT JOIN tenant_user b ON b.id=attendance.tenant_user_id " +
            "LEFT JOIN tenant c ON c.Id=attendance.tenant_id  ${ew.customSqlSegment}")
    IPage<Attendance> selectPage(Page<Attendance> page, @Param(Constants.WRAPPER) Wrapper<Attendance> queryWrapper);


    List<Attendance> findUserDay(@Param(value = "tenantId") Long tenantId, @Param(value = "type") Integer type,
                                 @Param(value = "departmentId") Long departmentId);
}
